package com.danger.Presenter;

import android.content.Context;

import com.danger.Model.action.SearchFoundModel;
import com.danger.Model.action.SearchFoundModelImpl;
import com.danger.Model.bean.ObjectInfo;
import com.danger.Model.listener.OnSearchListener;
import com.danger.View.SearchView;

import java.util.List;

/**
 * Created by danger on 2016/4/4.
 */
public class SearchFoundPresenterImpl implements SearchFoundPresenter {

    private Context context;
    private SearchFoundModel searchFoundModel;
    private SearchView searchView;

    public SearchFoundPresenterImpl(Context context, SearchView searchView) {
        this.context = context;
        this.searchView = searchView;
        searchFoundModel = new SearchFoundModelImpl(context);
    }

    @Override
    public void searchByCategory(String category) {
        searchView.showDialog();
        searchFoundModel.searchByCategory(category, new OnSearchListener() {
            @Override
            public void onSuccess(List<ObjectInfo> objectInfoList) {
                searchView.hideDialog();
                searchView.showSuccess(objectInfoList);
            }

            @Override
            public void onError(String s) {
                searchView.hideDialog();
                searchView.showError(s);
            }
        });
    }

    @Override
    public void searchByTitle(String title) {
        searchView.showDialog();
        searchFoundModel.searchByTitle(title, new OnSearchListener() {
            @Override
            public void onSuccess(List<ObjectInfo> objectInfoList) {
                searchView.hideDialog();
                searchView.showSuccess(objectInfoList);
            }

            @Override
            public void onError(String s) {
                searchView.hideDialog();
                searchView.showError(s);
            }
        });
    }

    @Override
    public void searchByIndistinct(String key, String value) {
        searchFoundModel.searchByIndistinct(key, value, new OnSearchListener() {
            @Override
            public void onSuccess(List<ObjectInfo> objectInfoList) {
                searchView.hideDialog();
                searchView.showSuccess(objectInfoList);
            }

            @Override
            public void onError(String s) {
                searchView.hideDialog();
                searchView.showError(s);
            }
        });
    }
}
